﻿app.datasource.project = (function ($) {

    var apiUrl = "/api/Projects";

    var dataSource = new kendo.data.DataSource({
        serverFiltering: true, // <-- Do filtering server-side
        serverPaging: true, // <-- Do paging server-side
        transport: {
            read: {
                url: apiUrl,
                dataType: "json",
                contentType: "application/json"
            },
            update: {
                url: function (project) {
                    return apiUrl + project.models[0].ProjectID
                },
                dataType: "json",
                type: "PUT",
                contentType: "application/json"
            },
            destroy: {
                url: function (project) {
                    return apiUrl + project.models[0].ProjectID
                },
                dataType: "json",
                type: "DELETE",
                contentType: "application/json"
            },
            create: {
                url: apiUrl,
                dataType: "json",
                type: "POST",
                contentType: "application/json"
            },
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    //return { project: kendo.stringify(options.models) };
                    return JSON.stringify(options.models[0]);
                }
            }

        },
        batch: true,
        pageSize: 20,
        schema: app.vm.project

    });

    return dataSource;

})($);